#include "windowview.h"

WindowView::WindowView(HWND hWnd)
{
	_hWnd = hWnd;
}

WindowView::~WindowView()
{

}

void WindowView::Draw(int x, int y)
{

	static bool s=false;

	LPCTSTR str= _T("Hello Roguelike");
	LPCTSTR stat= _T("Welcome! 환영합니다! 뜔땳歓迎(かんげい) いたします! ");

	int w,h;

		_hDc=BeginPaint(_hWnd,&_ps);

		GetClientRect(_hWnd, &_rect);


		_hDcMem = CreateCompatibleDC(_hDc); // double buffering
		_hBmMem = CreateCompatibleBitmap(_hDc, _rect.right, _rect.bottom);//3
		_hBmMemOld =(HBITMAP)SelectObject(_hDcMem, _hBmMem);//
		w = 10;
		h = -MulDiv(w, GetDeviceCaps(_hDcMem, LOGPIXELSY), 72);

		// 화면을 모두 까만색으로 채운다.
		BitBlt(_hDcMem, 0, 0, _rect.right, _rect.bottom, 0, 0, 0, BLACKNESS);
		SetBkMode(_hDcMem, TRANSPARENT);

		_hFont=CreateFont(h, 0, 0, 0,FW_NORMAL, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, PROOF_QUALITY, FF_MODERN, _T("FixedSys"));
				_hOldFont=(HFONT)SelectObject(_hDcMem,_hFont);

		// 글자 색깔은 여기서 정해요
		SetTextColor(_hDcMem, 0xFFFFFF);
		//DBG::tcout << " x : " << x << " y : " << y << DBG::endl;
		TextOut(_hDcMem,x,y,_T("@"),1);
		if( s )
			TextOut(_hDcMem,320,320,stat,_tcslen(stat));

		TextOut(_hDcMem, 48,48,str,_tcslen(str));

		SelectObject(_hDcMem,_hOldFont);
		DeleteObject(_hFont);

		BitBlt(_hDc, 0, 0, _rect.right, _rect.bottom, _hDcMem, 0, 0, SRCCOPY);

		SelectObject(_hDcMem, _hBmMemOld); //-4
		DeleteObject(_hBmMem); //-3
		DeleteDC(_hDcMem); //-2
		//ValidateRect(hWnd, NULL);

		EndPaint(_hWnd,&_ps);

}

void WindowView::Redraw()
{
	InvalidateRect(_hWnd, NULL, FALSE);
}
